home *** CD-ROM | disk | FTP | other *** search
- #
- # $Id: fit.dem,v 1.3 1995/04/06 14:01:53 drd Exp $
- #
-
- pause 0 "Some examples how data fitting using nonlinear least squares fit"
- pause 0 "can be done."
- pause 0 ""
- pause -1 "first plotting the pure data set (-> return)"
-
- plot 'lcdemo.dat'
- set xlabel "Temperature T [deg Cels.]"
- set ylabel "Density [g/cm3]"
-
- pause 0 "now fitting a straight line to the data :-)"
- pause 0 "only as a demo without physical meaning"
- load 'line.fnc'
- y0 = 0.0
- m = 0.0
- show variables
- pause -1 "first a plot with all parameters set to zero (-> return)"
- plot 'lcdemo.dat', l(x)
- pause -1 "now start fitting... (-> return)"
- fit l(x) 'lcdemo.dat' via y0, m
- pause -1 "now look at the result (-> return)"
- plot 'lcdemo.dat', l(x)
-
- pause -1 "see the influence of weights for single data points (-> return)"
- fit l(x) 'lcdemo.dat' using 1:2:3 via y0, m
- pause -1 "now look at the result (-> return)"
- plot 'lcdemo.dat', l(x)
-
- pause -1 "now prefer the high temperature data (-> return)"
- fit l(x) 'lcdemo.dat' using 1:2:4 via y0, m
- pause -1 "now look at the result (-> return)"
- plot 'lcdemo.dat', l(x)
-
- pause 0 "now use real single-measurement errors to reach such a result (-> return)"
- pause 0 "(look at the file lcdemo.dat and compare the columns to see the difference)"
- pause -1 "(-> return)"
- plot 'lcdemo.dat' using 1:2:5 with errorbars
- fit l(x) 'lcdemo.dat' using 1:2:5 via y0, m
- pause -1 "now look at the result (-> return)"
- plot 'lcdemo.dat' using 1:2:5 with errorbars, l(x)
-
- pause 0 "It's time now to try a more realistic model function"
- load 'density.fnc'
- show functions
- pause 0 "density(x) is a function which shall fit the whole temperature"
- pause 0 "range using a ?: expression. It contains 6 model parameters which
- pause 0 "will all be varied. Now take the start parameters out of the"
- pause -1 "file 'start.par' and plot the function (-> return)"
- load 'start.par'
- plot 'lcdemo.dat', density(x)
- fit density(x) 'lcdemo.dat' via 'start.par'
- pause -1 "now look at the result (-> return)"
- plot 'lcdemo.dat', density(x)
-
- pause 0 "looks already rather nice? We will do now the following: set"
- pause 0 "the epsilon limit higher so that we need more iteration steps"
- pause 0 "to convergence. During fitting please hit ctrl-C. You will be asked"
- pause 0 "Stop, Continue, Execute: Try everything. You may define a script"
- pause 0 "using the FIT_SCRIPT environment variable. An example would be"
- pause 0 "'FIT_SCRIPT=plot nonsense.dat'. Normally you don't need to set"
- pause 0 "FIT_SCRIPT since it defaults to 'replot'. Please note that FIT_SCRIPT"
- pause 0 "cannot be set from inside gnuplot."
- pause 0 ""
- pause -1 "(-> return)"
- FIT_LIMIT = 1e-10
- fit density(x) 'lcdemo.dat' via 'start.par'
- pause -1 "now look at the result (-> return)"
- plot 'lcdemo.dat', density(x)
-
- pause 0 ""
- pause 0 ""
- pause -1 "Now an example how to fit multi-branch functions (-> return)"
- plot 'soundvel.dat'
- pause 0 "The model consists of two branches, the first describing longitudinal"
- pause 0 "sound velocity as function of propagation direction (upper data),"
- pause 0 "the second describing transverse sound velocity (lower data)."
- pause 0 ""
- pause 0 "The model uses these data in order to fit elastic stiffnesses"
- pause 0 "which occur differently in both branches."
- pause 0 ""
- pause -1 "(-> return)"
- load 'hexa.fnc'
- load 'sound.par'
- plot 'soundvel.dat', vlong(x), vtrans(x)
- fit f(x) 'soundvel.dat' via 'sound.par'
- pause 0 ""
- pause -1 "(-> return)"
- plot 'soundvel.dat', vlong(x), vtrans(x)
- pause 0 "Look at the file 'hexa.fnc' to see how the branches are realized"
- pause 0 "using the internal variable FIT_INDEX"
- pause 0 ""
- pause 0 "Next we only use every fifth data point for fitting by using the"
- pause 0 "'every' keyword. Look at the fitting-speed increase and at"
- pause 0 "fitting result."
- pause 0 ""
- pause -1 "(-> return)"
- load 'sound.par'
- plot 'soundvel.dat', vlong(x), vtrans(x)
- # FIT_SKIP = 4
- fit f(x) 'soundvel.dat' every 5 via 'sound.par'
- plot 'soundvel.dat', vlong(x), vtrans(x)
- pause 0 "When you compare the results (see 'fit.log') you remark that"
- pause 0 "the uncertainties in the fitted constants have become larger,"
- pause 0 "the quality of the plot is only slightly affected."
- pause 0 ""
- pause 0 "By marking some parameters as '# FIXED' in the parameter file"
- pause 0 "you fit only the others (c44 and c13 fixed here)."
- pause 0 ""
- pause -1 "(-> return)"
- load 'sound2.par'
- plot 'soundvel.dat', vlong(x), vtrans(x)
- fit f(x) 'soundvel.dat' via 'sound2.par'
- plot 'soundvel.dat', vlong(x), vtrans(x)
- pause 0 "This has the same effect as specifying only the real free"
- pause 0 "parameters by the 'via' syntax."
- pause 0 ""
- pause 0 "fit f(x) 'soundvel.dat' via c33, c11, phi0"
- pause 0 ""
- pause -1 "(-> return)"
- load 'sound.par'
- plot 'soundvel.dat', vlong(x), vtrans(x)
- fit f(x) 'soundvel.dat' via c33, c11, phi0
- plot 'soundvel.dat', vlong(x), vtrans(x)
-
- pause 0 "Here comes an example of a very complex function..."
- pause 0 ""
- pause -1 "first plotting the pure data set (-> return)"
-
- set xlabel "Delta [degrees]"
- set ylabel "Reflectivity"
- plot 'moli3.dat'
-
- pause 0 "now fitting the model function to the data"
- load 'reflect.fnc'
-
- eta = 1.2e-2
- tc = 1.8e-3
-
- show variables
- show functions
- pause -1 "first a plot with all parameters set to initial values (-> return)"
- plot 'moli3.dat', R(x)
- pause -1 "now start fitting... (-> return)"
- fit R(x) 'moli3.dat' via eta, tc
- pause -1 "now look at the result (-> return)"
- plot 'moli3.dat', R(x)
-
- pause 0 "You can have a look at all previous fit results by looking into"
- pause 0 "the file 'fit.log' or whatever you defined the env-variable 'FIT_LOGFILE'."
- pause 0 "Remember that this file will always be appended, so remove it"
- pause 0 "from time to time!"
- pause 0 ""
-